package pl.edu.agh.neural.input;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class WeightsFromFileGenerator implements IWeightsGenerator {

    private Iterator<Double> weightsIterator;

    public WeightsFromFileGenerator(String filepath) throws IOException {
        List<String> lines = Files.readAllLines(Paths.get(filepath), Charset.forName("UTF-8"));
        String weightsLine = lines.get(0);
        String[] weightsStrings = weightsLine.split("\\s+");

        List<Double> weights = new ArrayList<>();
        for (String weightsString : weightsStrings) {
            weights.add(Double.parseDouble(weightsString));
        }
        weightsIterator = weights.iterator();
    }

    @Override
    public double nextWeight() {
        return weightsIterator.next();
    }
}
